<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自动登录</title>
    <script src="http://47.106.66.89:8080/js/vue.min.js"></script>
    <script src="http://47.106.66.89:8080/js/axios.min.js"></script>
    <script src="js/login.js"></script>
    <link  href="http://47.106.66.89:8080/js/ele-2.15.7/theme-chalk/index.css" rel="stylesheet">
    <script src="http://47.106.66.89:8080/js/ele-2.15.7/index.js"></script>
    <script src="/auth/js/auth.js"></script>
</head>
<body>
<div id="app">
    <h1>自动登录</h1>
    <login ref="login"></login>
    <hr>
    <button @click="showAutoLogin=true" v-if="showAutoLogin==false">扫码登录</button>
    <img v-else src="/user/autoLogin/askAutoLogin" style="width: 200px; height: 200px;"
        @load="canAutoLogin">
</div>
<script>
    var v = new Vue({
        el: "#app",
        data: {
            showAutoLogin: false,
        },
        methods:{
            canAutoLogin(){
                let uuid = document.cookie.replace(/.*uuid=([^;]+).*/,"$1");
                let handler = setInterval(()=>{
                    axios.get("/user/autoLogin/canAutoLogin?uuid="+uuid).then(res=>{
                       if(res.data.code == 1){
                           // 清除定时任务
                           clearInterval(handler);
                           // 发起登录(根据uid)
                           axios.get("/user/autoLogin/login?uid="+res.data.data).then(res=>{
                               // 跟新登录状态
                               this.$refs.login.myinfo = res.data.data;
                           })
                       }
                    });
                },1000);
            }
        }
    });
</script>
</body>
</html>